/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package au.edu.unsw.bookmarket.service.impl;

import au.edu.unsw.bookmarket.actionform.CourseBean;
import au.edu.unsw.bookmarket.actionform.PostAdsBean;
import au.edu.unsw.bookmarket.dao.CourseDao;
import au.edu.unsw.bookmarket.jdo.Course;
import au.edu.unsw.bookmarket.service.CourseService;
import au.edu.unsw.bookmarket.util.BeanMapping;
import java.util.List;

/**
 *
 * @author gongz
 */
public class CourseServiceImpl implements CourseService {

    CourseDao courseDao;

    public CourseDao getCourseDao() {
        return courseDao;
    }

    public void setCourseDao(CourseDao courseDao) {
        this.courseDao = courseDao;
    }

    public CourseBean addCourse(PostAdsBean postAdsBean) {
        BeanMapping beanMapping = new BeanMapping();
        CourseBean course = null;
        try {
            CourseBean courseBean = beanMapping.postAdsBean2CourseBean(postAdsBean);
            // add if not existence
            if (courseDao.courseExistency(courseBean) == null) {
                courseDao.addCourseAsCourseBean(courseBean);
            } else {
                return courseDao.courseExistency(courseBean);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return course;
    }

    public void addCourseDirectly(Course course) {
        try {
            courseDao.addCourse(course);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public List<CourseBean> getAllCourses() {
        return courseDao.getAllCourses();
    }

    public boolean removeAllCourses() {
        return courseDao.removeAllCourses();
    }
}
